import Vue from 'vue'
import Vuex from 'vuex'
import woman from '../../../../static/staticJC/images/event/woman.png'
import man from '../../../../static/staticJC/images/event/man.png'

Vue.use(Vuex)

const tx = {
    state: {
      txURL:woman
    },
    mutations: {
      setTx(state){
        wx.chooseImage({
          count: 1, // 默认9
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            let localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
            wx.uploadImage({
              localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
              isShowProgressTips: 1, // 默认为1，显示进度提示
              success: function (res) {
                let serverId = res.serverId; // 返回图片的服务器端ID
                ajaxCore.ajax(config.szg.downLoadImage, {"mediaId": serverId}, "GET", {
                  "Authorization": getToken()
                }).done(function(res){
                  let data = res;
                  if(data.status === 10001){
                    if(data.result != "" && data.result!= null){
                      state.txURL = data.result;
                    }
                  }else{
                    DYD.msg(data.desc);
                  }
                }).fail(function(data){
                  DYD.msg("获取图片失败");
                });
              }
            });
          }
        });
      }
    },
    actions: {
      ajaxTxArrAC(store){
        ajaxCore.ajax(config.szg.queryPic, null, "GET", {
          "Authorization": getToken()
        }).done(function(res){
          if(res.status === 10001){
            if(res.result !== ""){
              store.state.txURL = res.result;
            }else{
              ajaxCore.ajax(config.szg.getSex, null, "GET", {
                "Authorization": getToken()
              }).done(function(res1){
                if(res1.status === 10001){
                  switch (res1.result){
                    case 0:
                      store.state.txURL = man;
                      break;
                    case 1:
                      store.state.txURL = man;
                      break;
                    case 2:
                      store.state.txURL = woman;
                      break;
                    default:
                      store.state.txURL = man;
                  }
                }
              });
            }
          }
        });
      }
    }
};

export default tx  
